import { AppViewResource } from '@/global';
import http from '@/http/axios_config';

export interface UserToken {
  token: string;
  expire: Date
}

export interface AuthUser {
  username: string,
  userId: string,
  avater?: string,
  email?: string,
  github?: string,
  weixin?: string,
  userToken?: any
  viewResource?: any
}

export interface ViewResourceResponse {
  total?: number,
  data?: AppViewResource[]
}

export async function fetchViewResource() {
  try {
    return await http.get('/api/auth/view-resource');
  } catch (error: any) {
    return null;
  }
}
export async function fetchUserInfo() {
  try {
    return await http.get('/api/user');
  } catch (error: any) {
    return null;
  }
}

export async function fetchAuthToken(data: any) {
  return http.post('/api/auth/login', data);
}

export async function logout() {
  return http.get('/api/auth/logout');
}

export async function weixinCodeLogin(data: any) {
  return http.post('/api/auth/wx-code-login', data)
}